package com.ss.android.article.base.ui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.Transformation;
import android.widget.ImageView;

import com.ss.android.article.browser.R;

public class PullLoadingView extends ImageView {
    final class a {
        final Path a;
        private final PullLoadingView h;
        float b;
        float c;
        float d;
        float e;
        float f;
        float g;
        private final RectF i;
        private float j;

        public a(PullLoadingView arg2) {
            this.h = arg2;

            this.a = new Path();
            this.i = new RectF();
        }

        public final void a(float arg10) {
            float v7 = 360f;
            if (this.j != arg10) {
                this.j = arg10;
                this.a.reset();
                float v1 = this.g * arg10;
                float v3 = this.h.f / 2f;
                float v0 = v1 > this.d ? this.d : v1;
                v1 -= v0;
                if (v0 <= 0f) {
                    return;
                }

                v0 = v0 * v7 / this.e;
                this.i.set((((float) this.h.b)) - this.c - v3, v3, (((float) this.h.b)) - v3, this.c + v3);
                this.a.addArc(this.i, 0f, -v0);
                v0 = v1 > this.f ? this.f : v1;
                v1 -= v0;
                if (v0 <= 0f) {
                    return;
                }

                this.a.moveTo((((float) this.h.b)) - this.b - v3, v3);
                this.a.lineTo((((float) this.h.b)) - this.b - v3 - v0, v3);
                v0 = v1 > this.d ? this.d : v1;
                v1 -= v0;
                if (v0 <= 0f) {
                    return;
                }

                v0 = v0 * v7 / this.e;
                this.i.set(v3, v3, this.c + v3, this.c + v3);
                this.a.addArc(this.i, -90f, -v0);
                v0 = v1 > this.f ? this.f : v1;
                v1 -= v0;
                if (v0 <= 0f) {
                    return;
                }

                this.a.moveTo(v3, this.b + v3);
                this.a.lineTo(v3, v0 + this.b + v3);
                v0 = v1 > this.d ? this.d : v1;
                v1 -= v0;
                if (v0 <= 0f) {
                    return;
                }

                v0 = v0 * v7 / this.e;
                this.i.set(v3, (((float) this.h.c)) - this.c - v3, this.c + v3, (((float) this.h.c)) - v3);
                this.a.addArc(this.i, -180f, -v0);
                v0 = v1 > this.f ? this.f : v1;
                float v2 = v1 - v0;
                if (v0 <= 0f) {
                    return;
                }

                this.a.moveTo(this.b + v3, (((float) this.h.c)) - v3);
                this.a.lineTo(v0 + this.b + v3, (((float) this.h.c)) - v3);
                v1 = v2 > this.d ? this.d : v2;
                v0 = v2 - v1;
                if (v1 <= 0f) {
                    return;
                }

                v1 = v1 * v7 / this.e;
                this.i.set((((float) this.h.b)) - this.c - v3, (((float) this.h.c)) - this.c - v3, (((float) this.h.b)) - v3, (((float) this.h.c)) - v3);
                this.a.addArc(this.i, -270f, -v1);
                if (v0 > this.f) {
                    v0 = this.f;
                }

                if (v0 <= 0f) {
                    return;
                }

                this.a.moveTo((((float) this.h.b)) - v3, (((float) this.h.c)) - this.b - v3);
                this.a.lineTo((((float) this.h.b)) - v3, (((float) this.h.c)) - this.b - v3 - v0);
            }
        }
    }

    final class b {
        final Path a;
        private final PullLoadingView f;
        float b;
        float c;
        float d;
        float e;
        private float g;

        public b(PullLoadingView arg2) {
            this.f = arg2;

            this.a = new Path();
        }

        public final void a(float arg8) {
            float v1 = 0.5f;
            if (this.g != arg8) {
                this.g = arg8;
                this.a.reset();
                if (arg8 > v1) {
                    v1 = 3f * ((arg8 - v1) / v1 * this.b);
                    int v0 = 0;
                    do {
                        float v2 = v1 > this.b ? this.b : v1;
                        v1 -= v2;
                        if (v2 <= 0f) {
                            return;
                        }

                        float v3 = this.c + this.e * (((float) v0));
                        this.a.moveTo(this.d, v3);
                        this.a.lineTo(this.d + v2, v3);
                        if (v2 <= 0f) {
                            return;
                        }

                        ++v0;
                    }
                    while (v0 < 3);
                }
            }
        }
    }

    final class c {
        final Path a;
        final Path b;
        final Paint c;
        final RectF d;
        private final PullLoadingView i;
        int e;
        float f;
        float g;
        float h;
        private float j;

        public c(PullLoadingView arg3) {
            this.i = arg3;

            this.e = ContextCompat.getColor(arg3.a, R.color.oy);
            this.a = new Path();
            this.b = new Path();
            this.c = new Paint(5);
            this.c.setColor(this.e);
            this.d = new RectF();
        }

        public final void a(float arg8) {
            float v0 = 0.25f;
            if (this.j != arg8) {
                this.j = arg8;
                this.a.reset();
                this.b.reset();
                if (arg8 > v0) {
                    arg8 = v0;
                }

                float v3 = this.i.f / 2f;
                float v1 = this.f * (arg8 / v0);
                v0 = v1 > this.d.width() ? this.d.width() : v1;
                v1 -= v0;
                if (v0 <= 0f) {
                    return;
                }

                this.a.moveTo(this.d.right, this.d.top + v3);
                this.a.lineTo(this.d.right - v0, this.d.top + v3);
                this.b.moveTo(this.d.right, this.d.top);
                this.b.lineTo(this.d.right - v0, this.d.top);
                v0 = v1 > this.d.height() ? this.d.height() : v1;
                float v2 = v1 - v0;
                if (v0 <= 0f) {
                    return;
                }

                this.a.moveTo(this.d.left + v3, this.d.top);
                this.a.lineTo(this.d.left + v3, this.d.top + v0);
                this.b.lineTo(this.d.left, v0 + this.d.top);
                v1 = v2 > this.d.width() ? this.d.width() : v2;
                v0 = v2 - v1;
                if (v1 <= 0f) {
                    return;
                }

                this.a.moveTo(this.d.left, this.d.bottom - v3);
                this.a.lineTo(this.d.left + v1, this.d.bottom - v3);
                this.b.lineTo(v1 + this.d.left, this.d.bottom);
                if (v0 > this.d.height()) {
                    v0 = this.d.height();
                }

                if (v0 <= 0f) {
                    return;
                }

                this.a.moveTo(this.d.right - v3, this.d.bottom);
                this.a.lineTo(this.d.right - v3, this.d.bottom - v0);
                this.b.lineTo(this.d.right, this.d.bottom - v0);
            }
        }
    }

    final class d extends Animation {
        private final PullLoadingView a;

        d(PullLoadingView arg1, byte arg2) {
            this(arg1);
        }

        private d(PullLoadingView arg1) {
            this.a = arg1;

        }

        protected final void applyTransformation(float arg11, Transformation arg12) {
            float v6;
            float v3;
            float v9 = 0.07f;
            float v2 = 0.05f;
            float v8 = 1f;
            float v5 = 2f;
            PullLoadingView v4 = this.a;
            v4.g.a(v8);
            c v0 = v4.j;
            v0.a(v8);
            if (arg11 < 0.065f) {
                label_225:
                v0.g = 0f;
                v0.h = 0f;
            } else if (arg11 < 0.115f) {
                v0.g = (arg11 - 0.065f) / v2 * ((((float) v0.i.b)) - v0.d.centerX() * v5);
                v0.h = 0f;
            } else if (arg11 < 0.315f) {
                v0.g = (((float) v0.i.b)) - v0.d.centerX() * v5;
                v0.h = 0f;
            } else if (arg11 < 0.365f) {
                v0.g = (((float) v0.i.b)) - v0.d.centerX() * v5;
                v0.h = (arg11 - 0.315f) / v2 * ((((float) v0.i.c)) - v0.d.centerY() * v5);
            } else if (arg11 < 0.565f) {
                v0.g = (((float) v0.i.b)) - v0.d.centerX() * v5;
                v0.h = (((float) v0.i.c)) - v0.d.centerY() * v5;
            } else if (arg11 < 0.615f) {
                v0.g = (v8 - (arg11 - 0.565f) / v2) * ((((float) v0.i.b)) - v0.d.centerX() * v5);
                v0.h = (((float) v0.i.c)) - v0.d.centerY() * v5;
            } else if (arg11 < 0.815f) {
                v0.g = 0f;
                v0.h = (((float) v0.i.c)) - v0.d.centerY() * v5;
            } else if (arg11 < 0.865f) {
                v0.g = 0f;
                v0.h = (v8 - (arg11 - 0.815f) / v2) * ((((float) v0.i.c)) - v0.d.centerY() * v5);
            } else {
                v0.g = 0f;
                v0.h = 0f;
            }

            e v5_1 = v4.h;
            v5_1.a(v8);
            v2 = v5_1.d;
            float v1 = v5_1.b + v5_1.d;
            float v0_1 = v5_1.c;
            if (arg11 >= 0.075f) {
                if (arg11 < 0.195f) {
                    v0_1 = (arg11 - 0.075f) / 0.12f;
                    v2 = v5_1.d - (v5_1.d - v5_1.f.d) * v0_1;
                    v0_1 = v0_1 * (v5_1.f.i.c - v5_1.c) + v5_1.c;
                } else if (arg11 < 0.325f) {
                    v2 = v5_1.f.d;
                    v0_1 = v5_1.f.i.c;
                } else if (arg11 < 0.395f) {
                    v3 = (((float) (v5_1.f.b / 2))) - v5_1.f.e;
                    v2 = v5_1.f.d;
                    v1 -= (arg11 - 0.325f) / v9 * (v1 - v3);
                    v0_1 = v5_1.f.i.c;
                } else if (arg11 < 0.575f) {
                    v2 = v5_1.f.d;
                    v1 = (((float) (v5_1.f.b / 2))) - v5_1.f.e;
                    v0_1 = v5_1.f.i.c;
                } else if (arg11 < 0.695f) {
                    v0_1 = (arg11 - 0.575f) / 0.12f;
                    v3 = (((float) (v5_1.f.b / 2))) - v5_1.f.e;
                    v2 = v5_1.f.d;
                    v1 = (v1 - v3) * v0_1 + v3;
                    v0_1 = v5_1.f.i.c - v0_1 * (v5_1.f.i.c - v5_1.c);
                } else if (arg11 < 0.825f) {
                    v2 = v5_1.f.d;
                } else if (arg11 < 0.895f) {
                    v2 = (arg11 - 0.825f) / v9 * (v5_1.d - v5_1.f.d) + v5_1.f.d;
                }
            }

            v5_1.a.reset();
            int v3_1 = 0;
            do {
                v6 = v5_1.e * (((float) v3_1)) + v0_1;
                v5_1.a.moveTo(v2, v6);
                v5_1.a.lineTo(v1, v6);
                ++v3_1;
            }
            while (v3_1 < 3);

            b v5_2 = v4.i;
            v5_2.a(v8);
            v2 = v5_2.d;
            v1 = v5_2.b + v5_2.d;
            v0_1 = v5_2.c;
            if (arg11 >= 0.075f) {
                if (arg11 < 0.145f) {
                    v3 = (arg11 - 0.075f) / v9;
                    v1 -= (v1 - ((((float) (v5_2.f.b / 2))) - v5_2.f.e)) * v3;
                    v0_1 -= v3 * (v5_2.c - v5_2.f.h.c);
                } else if (arg11 < 0.325f) {
                    v1 = (((float) (v5_2.f.b / 2))) - v5_2.f.e;
                    v0_1 = v5_2.f.h.c;
                } else if (arg11 < 0.445f) {
                    v1 = v5_2.d + v5_2.b;
                    v3 = (((float) (v5_2.f.b / 2))) - v5_2.f.e;
                    v1 = v3 + (arg11 - 0.325f) / 0.12f * (v1 - v3);
                    v0_1 = v5_2.f.h.c;
                } else if (arg11 < 0.575f) {
                    v0_1 = v5_2.f.h.c;
                } else if (arg11 < 0.645f) {
                    v0_1 = (arg11 - 0.575f) / v9;
                    v2 += (v5_2.f.h.d - v2) * v0_1;
                    v0_1 = v0_1 * (v5_2.c - v5_2.f.h.c) + v5_2.f.h.c;
                } else if (arg11 < 0.825f) {
                    v2 = v5_2.f.h.d;
                } else if (arg11 < 0.945f) {
                    v2 = v5_2.f.h.d - (v5_2.f.h.d - v2) * ((arg11 - 0.825f) / 0.12f);
                }
            }

            v5_2.a.reset();
            v3_1 = 0;
            do {
                v6 = v5_2.e * (((float) v3_1)) + v0_1;
                v5_2.a.moveTo(v2, v6);
                v5_2.a.lineTo(v1, v6);
                ++v3_1;
            }
            while (v3_1 < 3);

            v4.invalidate();
        }
    }

    final class e {
        final Path a;
        private final PullLoadingView f;
        float b;
        float c;
        float d;
        float e;
        private float g;

        public e(PullLoadingView arg2) {
            this.f = arg2;

            this.a = new Path();
        }

        public final void a(float arg8) {
            float v0 = 0.5f;
            float v2 = 0.25f;
            if (this.g != arg8) {
                this.g = arg8;
                this.a.reset();
                if (arg8 > v2) {
                    if (arg8 > v0) {
                        arg8 = v0;
                    }

                    float v1 = 3f * ((arg8 - v2) / v2 * this.b);
                    int v0_1 = 0;
                    do {
                        v2 = v1 > this.b ? this.b : v1;
                        v1 -= v2;
                        if (v2 <= 0f) {
                            return;
                        }

                        float v3 = this.c + this.e * (((float) v0_1));
                        this.a.moveTo(this.d, v3);
                        this.a.lineTo(this.d + v2, v3);
                        if (v2 <= 0f) {
                            return;
                        }

                        ++v0_1;
                    }
                    while (v0_1 < 3);
                }
            }
        }
    }

    Context a;
    int b;
    int c;
    float d;
    float e;
    float f;
    a g;
    e h;
    b i;
    c j;
    private int k;
    private float l;
    private float m;
    private Paint n;
    private float o;
    private Paint p;
    private float q;
    private boolean r;
    private float s;

    public PullLoadingView(Context arg1) {
        super(arg1);
        this.a(arg1);
    }

    public PullLoadingView(Context arg1, AttributeSet arg2) {
        super(arg1, arg2);
        this.a(arg1);
    }

    public PullLoadingView(Context arg1, AttributeSet arg2, int arg3) {
        super(arg1, arg2, arg3);
        this.a(arg1);
    }

    private void a(Context arg3) {
        this.a = arg3;
        this.k = ContextCompat.getColor(this.a, R.color.b3);
        this.q = 1f;
        this.n = new Paint(5);
        this.n.setStyle(Paint.Style.STROKE);
        this.n.setColor(this.k);
        this.p = new Paint(this.n);
        this.g = new a(this);
        this.h = new e(this);
        this.i = new b(this);
        this.j = new c(this);
    }

    public void clearAnimation() {
        if (this.getAnimation() != null) {
            super.clearAnimation();
            c v0 = this.j;
            v0.g = 0f;
            v0.h = 0f;
        }
    }

    public float getPullProgress() {
        return this.s;
    }

    protected void onDraw(Canvas arg4) {
        super.onDraw(arg4);
        a v0 = this.g;
        if (!v0.a.isEmpty()) {
            arg4.drawPath(v0.a, v0.h.n);
        }

        e v0_1 = this.h;
        if (!v0_1.a.isEmpty()) {
            arg4.drawPath(v0_1.a, v0_1.f.p);
        }

        b v0_2 = this.i;
        if (!v0_2.a.isEmpty()) {
            arg4.drawPath(v0_2.a, v0_2.f.p);
        }

        c v0_3 = this.j;
        arg4.translate(v0_3.g, v0_3.h);
        if (!v0_3.b.isEmpty()) {
            arg4.drawPath(v0_3.b, v0_3.c);
        }

        if (!v0_3.a.isEmpty()) {
            arg4.drawPath(v0_3.a, v0_3.i.n);
        }

        arg4.translate(-v0_3.g, -v0_3.h);
    }

    protected void onSizeChanged(int arg10, int arg11, int arg12, int arg13) {
        float v6 = 4f;
        float v8 = 0.272f;
        float v7 = 2f;
        super.onSizeChanged(arg10, arg11, arg12, arg13);
        if (arg10 > 0 && arg11 > 0 && arg10 == arg11) {
            this.b = arg10;
            this.c = arg11;
            float v0 = Math.max((((float) this.b)) / 48f, this.q);
            this.f = v0;
            this.o = v0 * v7;
            this.l = ((((float) arg10)) * v8 - this.o) / v7;
            this.d = (((float) arg10)) * 0.15f;
            this.e = (((float) arg10)) * 0.08f;
            this.m = (((float) arg10)) * 0.19f;
            this.n.setStrokeWidth(this.f);
            this.p.setStrokeWidth(this.o);
            a v0_1 = this.g;
            v0_1.b = (((float) arg10)) * 0.2f;
            v0_1.c = v0_1.b * v7;
            v0_1.f = (((float) arg10)) - v0_1.c - v0_1.h.f;
            v0_1.e = ((float) (3.141593 * (((double) v0_1.c))));
            v0_1.d = v0_1.e / v6;
            v0_1.g = v0_1.f * v6 + v0_1.e;
            c v0_2 = this.j;
            v0_2.d.set(v0_2.i.d, v0_2.i.m, v0_2.i.d + (((float) arg10)) * 0.35f, v0_2.i.m + (((float) arg11)) * v8);
            ((PullLoadingView.c) v0_2).f = (((c) v0_2).d.width() + ((c) v0_2).d.height()) * v7;
            e v0_3 = this.h;
            v0_3.b = (((float) arg10)) * 0.27f;
            v0_3.d = (((float) (v0_3.f.b / 2))) + v0_3.f.e;
            v0_3.e = v0_3.f.l;
            v0_3.c = v0_3.f.m + v0_3.f.o / v7;
            b v0_4 = this.i;
            v0_4.b = (((float) arg10)) * 0.7f;
            v0_4.d = v0_4.f.d;
            v0_4.e = v0_4.f.l;
            v0_4.c = (((float) v0_4.f.c)) - v0_4.f.m - (((float) arg10)) * v8 + v0_4.f.o / v7;
        }
    }

    public void setImageBitmap(Bitmap arg1) {
    }

    public void setImageDrawable(Drawable arg1) {
    }

    public void setImageResource(int arg1) {
    }

    public void setImageURI(Uri arg1) {
    }

    public void setPullProgress(float arg4) {
        float v0 = 1f;
        if (arg4 > v0) {
            arg4 = v0;
        } else if (arg4 < 0f) {
            arg4 = 0f;
        }

        if (this.s != arg4) {
            this.s = arg4;
            if (this.b > 0 && this.c > 0) {
                this.clearAnimation();
                this.g.a(this.s);
                this.j.a(this.s);
                this.h.a(this.s);
                this.i.a(this.s);
                this.invalidate();
            }
        }
    }

    public void setTheme(boolean arg4) {
        if (this.r != arg4) {
            this.r = arg4;
            this.k = ContextCompat.getColor(this.a, R.color.b3);
            this.n.setColor(this.k);
            this.p.setColor(this.k);
            c v0 = this.j;
            v0.e = ContextCompat.getColor(v0.i.a, R.color.oy);
            v0.c.setColor(v0.e);
        }
    }

    public void startAnimation(Animation arg3) {
        d v3 = null;
        this.clearAnimation();
        if (!(arg3 instanceof d)) {
            v3 = new d(this, (byte) 0);
            ((Animation) v3).setDuration(2000);
            ((Animation) v3).setRepeatCount(-1);
            ((Animation) v3).setRepeatMode(1);
            ((Animation) v3).setInterpolator(new LinearInterpolator());
        }

        super.startAnimation(v3);
    }
}

